import { observable, action, computed } from "mobx";
import { Bubble } from "weaver-mobile";
import * as api from "../../apis/blessCard";

export class HrmBlessCardStore {
    bcInnnerMarginTop = 20;
    blessCardMarginTop = 20;
    blessingMarginTop = 20;
    blessingLineHeight = 40;

    @observable blessing = "";
    @observable createDate = "";
    @observable creator = "";
    @observable imgUrl = "";
    @observable blessCardRef = null;
    @observable infoHeight = 0;

    @computed get blessingHeight() {
        const contentHeight = window.innerHeight - this.bcInnnerMarginTop * 2;

        return contentHeight - (this.getBlessCardHeight() + this.blessCardMarginTop + this.blessingMarginTop);
    }

    @computed get blessRowNumber() {
        const h = (this.infoHeight > this.blessingHeight) ? this.infoHeight : this.blessingHeight;
        return Math.floor(h / this.blessingLineHeight);
    }

    @action readBirthdayBlessingData = (id) => {
        api.readBirthdayBlessingData({ id }).then(res => {
            if (res.status == "1") {
                Object.keys(res).forEach(key => this[key] = res[key]);
            } else {
                Bubble.error(res.message);
            }
        })
    }

    @action setInfoHeight = (height) => {
        this.infoHeight = height;
    }

    getBlessCardHeight = () => {
        const ratio = 1.33;
        const blessCardWidth = (window.innerWidth - this.bcInnnerMarginTop * 2) * 0.7;
        return blessCardWidth * ratio
    }

}